export default (_enums) => {
  const texts = _enums.map((item) => item.text);
  const values = _enums.map((item) => item.value);
  const names = _enums.map((item) => item.name);
  const defaultValue = _enums.find((item) => item.default)?.value;
  const constant = {};
  _enums.forEach(({ name, value }) => {
    constant[name] = value;
  });

  const getValueByText = (text) => {
    return values[texts.indexOf(text)];
  };

  const getTextByValue = (value) => {
    return texts[values.indexOf(value)];
  };

  const getEnumByName = (name) => {
    return _enums[names.indexOf(name)];
  };

  const enums = _enums.map(({ value, text }) => {
    return { value, text };
  });

  return {
    ...constant,
    texts,
    values,
    enums,
    names,
    defaultValue,
    getValueByText,
    getTextByValue,
    getEnumByName
  };
};
